import { http } from "@/utils/http";
import type { PersistentVolumeClaimList, PersistentVolumeClaim } from "./types";
import type { BaseResponse } from "@/api/response";
import {
  k8sPathMergeReqs,
  type MakePathReq,
  type MergePathReq
} from "./apiHelper";

export class K8sPersistentVolumeClaim {
  baseReq: MakePathReq = {
    src: "persistentvolumeclaims",
    app: ""
  };

  getPVC = (query: MergePathReq): BaseResponse<PersistentVolumeClaimList> => {
    const api = k8sPathMergeReqs(query, this.baseReq);

    return http.get(api);
  };

  getPVCDetails = (
    query: MergePathReq
  ): BaseResponse<PersistentVolumeClaim> => {
    const api = k8sPathMergeReqs(query, this.baseReq);

    return http.get(api, { params: query.query });
  };

  createPVC = (
    query: MergePathReq,
    data?: PersistentVolumeClaim
  ): BaseResponse => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);

    return http.post(api, { data });
  };

  updatePVC = (
    query: MergePathReq,
    data?: PersistentVolumeClaim
  ): BaseResponse => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);

    return http.put(api, { data });
  };

  deletePVC = (
    query: MergePathReq,
    data?: PersistentVolumeClaim
  ): BaseResponse => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);
    return http.delete(api, { data });
  };
}
